package jk.spider.core.impl;

import jk.spider.api.event.EventSink;
import jk.spider.core.Content;
import jk.spider.core.SpiderController;
import jk.spider.core.dispatch.EventDispatcher;
import jk.spider.core.event.URLFound.URLFound;
import jk.spider.core.storage.Storage;
import jk.spider.core.throttle.Throttle;
import jk.spider.util.cheat.SpiderCheat;
import jk.spider.util.config.ConfigConstants;
import jk.spider.util.config.PropertySet;
import jk.spider.util.config.SpiderConfiguration;

public class SpiderControllerImpl implements SpiderController {

	protected Content content;
	protected Storage storage;
	protected EventDispatcher dispatcher;
	protected SpiderCheat cheat;
	protected PropertySet property;
	protected EventSink [] eventSink;
	protected URLFound [] urlFound;
	protected String cookie;
	protected String outputFile;
	protected Throttle throttle;
	protected String site;
	protected String visitorPatten;
	protected SpiderConfiguration spiderConfig;
	private String projectPath;
	
	public SpiderControllerImpl(Storage storage, URLFound [] urlFound, Throttle throttle, PropertySet property, SpiderConfiguration spiderConfig, String visitorPatten, String projectPath ) {
		this.storage = storage;
		this.property = property;
		this.urlFound = urlFound;
		this.throttle = throttle;
		this.spiderConfig = spiderConfig;
		this.visitorPatten = visitorPatten;
		this.projectPath = projectPath;
	}
	
	public void cheat() {
		cheat.execute();
	}
	
	public String getSite() {
		return this.getSpiderConfiguration().getSiteConfiguration().getString(ConfigConstants.SITE_TITLE, "");
	}
	
	public String getVisitorPatten() {
		return this.visitorPatten;
	}
	
	public void setCheat(SpiderCheat cheat) {
		this.cheat = cheat;
	}
	
	public Content getContent() {
		return content;
	}

	public String getCookie() {
		
		return cookie;
	}

	public EventDispatcher getEventDispatcher() {
		return dispatcher;
	}

	public PropertySet getProperty() {
		return property;
	}

	public void setCookie(String cookie) {
		this.cookie = cookie;
	}

	public Storage getStorage() {
		return storage;
	}

	public void setContent(Content content) {
		this.content = content;
	}

	public void setEventDispatcher(EventDispatcher dispatcher) {
		this.dispatcher = dispatcher;
	}

	public String getOutputFile() {
		return outputFile;
	}

	public void setOutputFile(String file) {
		this.outputFile = file;
	}

	public URLFound[] getURLFound() {
		return urlFound;
	}

	public void thottle() {
		throttle.throttle();
	}
	
	public SpiderConfiguration getSpiderConfiguration() {
		return spiderConfig;
	}
	
	public String getProjectPath() {
		return projectPath;
	}
}
